package com.wtwd.campus.receiver;

import com.wtwd.campus.entity.MqWifiData;
import com.wtwd.campus.service.InjectFeignService;
import org.apache.commons.lang.StringUtils;

/**
 * @Author ldaoliang
 * @Date create in 13:32 2021/6/9
 * @Description
 */
public class WifiMacReceiver implements Receiver {

    @Override
    public String parseMessage(String data) {
        // *WT,800115470000876,WIFIMAC,152715,106,0,81,0,5,d4:ee:07:15:39:fe,-74,28:94:0f:f9:c4:85,-80,a0:63:91:6a:d4:ba,-85,1c:78:39:0b:3d:dd,-87,06:1b:6d:c8:3f:85,-89,090621,FFFFFFDF#
        String[] split = data.split(",");
        String imei = split[1];
        String messageType = split[2];
        String commandNumber = split[3];
        String gsm = split[4];
        String gps = split[5];
        String bat = split[6];
        String step = split[7];   // 步数
        String wifiNum = split[8];
        int num = Integer.parseInt(wifiNum);
        String date=split[split.length-2];
        String wifiInfo = "";
        //wifi信息:mac地址,信号强度,wifi名称|mac地址,信号强度,wifi名称
        for (int i = 0; i < num; i++) {
            if(StringUtils.isNotBlank(wifiInfo)){
                wifiInfo =wifiInfo.concat("|");
        }
            wifiInfo =wifiInfo.concat(split[9 + 2*i]).concat(",").concat(split[10 + 2*i]);
        }
        MqWifiData mqWifiData = new MqWifiData();
        mqWifiData.setImei(imei);
        mqWifiData.setBattery(Integer.parseInt(bat));
        mqWifiData.setCommandNumber(commandNumber);
        mqWifiData.setDeviceTime(commandNumber);
        mqWifiData.setWifiInfo(wifiInfo);
        mqWifiData.setStepNum(Integer.parseInt(step));
        mqWifiData.setDeviceDate(date);
        InjectFeignService.getIrmFeignClientService().uploadWifiMac(mqWifiData);
        return imei;
    }
}
